package Day8Zuoye;

import java.io.*;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

public class Login extends Thread {
    private final Socket s;

    private static Map<String,String> users=new HashMap<>();
    static{
        users.put("wdnmd","666");
    }
    public Login(Socket s){
        this.s=s;
    }

    @Override
    public void run() {
        System.out.println("socket连接建立了。。。" + s);
        try {
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            PrintWriter pw = new PrintWriter(out, true);
            String name=br.readLine();
            String pass=br.readLine();
            if(pass.equals(users.get(name))){
                pw.println("登录成功");
            }else{
                pw.println("登录失败！");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                s.close();
                System.out.println(s+"关闭了。。。聊天结束");
            } catch (Exception e) {

            }
        }
    }

}
